package cn.scxy.bookcity.service.impl;

import cn.scxy.bookcity.ex.ServiceException;
import cn.scxy.bookcity.mapper.HotSearchMapper;
import cn.scxy.bookcity.mapper.UserIndexMapper;
import cn.scxy.bookcity.mapper.ZZRShoppingCarMapper;
import cn.scxy.bookcity.pojo.dto.UserLoginDTO;
import cn.scxy.bookcity.pojo.entity.Notice;
import cn.scxy.bookcity.pojo.vo.*;
import cn.scxy.bookcity.service.IUserIndexService;
import cn.scxy.bookcity.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;
@Slf4j
@Service
public class UserIndexServce implements IUserIndexService{
    @Autowired
    UserIndexMapper mapper;
    @Autowired
    HotSearchMapper hotSearchMapper;
    @Autowired
    ZZRShoppingCarMapper zzrShoppingCarMapper;

    @Override
    public List<ZZRCategoryListVOZZR> selectCategoryById(Long id) {
        log.debug("处理查询类别的service,方法selectCategory");
        List<ZZRCategoryListVOZZR> list = mapper.selectCategoryById(id);
        return list;
    }

    @Override
    public List<ZZRCategoryListVOZZR> selectCategoryChildrenById(Long id) {
        log.debug("处理查询类别的service,方法selectCategoryChildrenById");
        List<ZZRCategoryListVOZZR> list = mapper.selectCategoryChildrenById(id);
        return list;
    }

    @Override
    public List<ZZRCategoryListVOZZR> selectCategory() {
        log.debug("处理查询类别的service,方法selectCategory");
        List<ZZRCategoryListVOZZR> list = mapper.selectCategory();
        return list;
    }
    @Override
    public List<ZZRCategoryListVOZZR> selectCategoryParent() {
        log.debug("处理查询类别的service,selectCategoryParent");
        List<ZZRCategoryListVOZZR> list = mapper.selectCategoryParent();
        return list;
    }

    @Override
    public List<HotSearchListVO> selectHotSearchList() {
        log.debug("处理查询热搜的service,selectHotSearchList");
        List<HotSearchListVO> list = hotSearchMapper.selectHotSearchList();
        return list;
    }
    @Override
    public int countSoppingCar(Long id) {
        log.debug("处理统计购物车数量的countSoppingCar");
       int i=zzrShoppingCarMapper.countSoppingCar(id);
        return i;
    }

    @Override
    public List<GoodsListItemVO> selectGoodsListByNums() {
        log.debug("处理查询商品销量排序的service,selectGoodsListByNums");
        List<GoodsListItemVO> list= mapper.selectGoodsListByNums();
        return list;
    }

    @Override
    public List<GoodsListItemVO> selectGoodsListByComments() {
        log.debug("处理查询商品评论排序的service,selectGoodsListByComments");
        List<GoodsListItemVO> list= mapper.selectGoodsListByComments();
        return list;
    }
    @Override
    public List<GoodsListItemVO> selectGoodsListByNumsAll() {
        log.debug("处理查询商品销量排序的service,selectGoodsListByNums");
        List<GoodsListItemVO> list= mapper.selectGoodsListByNumsAll();
        return list;
    }
    @Override
    public List<GoodsListItemVO> selectGoodsListByCommentsAll() {
        log.debug("处理查询商品全部评论排序的service,selectGoodsListByCommentsAll");
        List<GoodsListItemVO> list= mapper.selectGoodsListByCommentsAll();
        return list;
    }

    @Override
    public UserLoginDTO getUserLogin(HttpSession session) {
       UserLoginDTO userLoginDTO=(UserLoginDTO) session.getAttribute("user");
       if(userLoginDTO.getPhone()!=null) {
           UserLoginDTO user= mapper.selectUserLogin(userLoginDTO.getPhone());
           return user;
       }
      throw new ServiceException(ServiceCode.ERR_SELECT,"未登录");
    }

    @Override
    public List<ActivityListVO> selectActivity() {
        List<ActivityListVO> list= mapper.selectActivity();
        return list;
    }

    @Override
    public List<Notice> selectNotice() {
        List<Notice> n=   mapper.selectNotice();
        return n;
    }


}
